/*
 * Created by: vadikv
 * Created: Sunday, March 16, 2008
 */

using System.Collections.Generic;
using OneDayModel.Services;
using TestUtils;

namespace OneDayModel.Tests.Mocks
{
    public class MockMailSender : IMailSender
    {

        public void SendMail(string email, MailContext mailContext)
        {
            if (ContextManager.TestContext[GetType().Name] == null)
            {
                ContextManager.TestContext[GetType().Name] = new List<SentMail>();
            }
            ((List<SentMail>)ContextManager.TestContext[GetType().Name]).Add(
                new SentMail() { eMail = email, mailContext = mailContext });
        }

        public static string GetSentMails()
        {
            List<SentMail> sentMails = (List<SentMail>) ContextManager.TestContext[typeof(MockMailSender).Name];
            string result="", separator="";
            foreach (SentMail sentMail in sentMails)
            {
                result += (separator +
                           string.Format("email={0} subject={1} body={2}", sentMail.eMail, sentMail.mailContext.Subject,
                                         sentMail.mailContext.Body));
                separator = ";";
            }
            return result;
        }
    }

    internal struct SentMail
    {
        public string eMail;
        public MailContext mailContext;
    }
}